from rest_framework.viewsets import ModelViewSet
from rest_framework.permissions import IsAdminUser
from django.contrib.auth.models import Group, Permission
from rest_framework.response import Response

from meiduo_admin.utils import PageNum
from meiduo_admin.serializers.groups import GroupSerializer
from meiduo_admin.serializers.permissions import PermissionSerializer


class GroupView(ModelViewSet):
    queryset = Group.objects.all()
    permission_classes = [IsAdminUser]
    pagination_class = PageNum
    serializer_class = GroupSerializer

    def simple(self, request):
        data = Permission.objects.all()
        ser = PermissionSerializer(data, many=True)
        return Response(ser.data)
